package com.zzl.pensionorder.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.zzl.entiey.PsOrders;
import com.zzl.pensionorder.service.OrderService;
import com.zzl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: OrderController
 * @Description: GOOD
 * @author: ZZL
 * @date: 2021/7/8  11:17
 */
@RestController
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("/order/save")
    public Result saveOrders(@RequestBody PsOrders psOrders){
       psOrders.setOd_date(new Date());
       orderService.saveOrder(psOrders);
       orderService.deleteGoodsNumberByGoodsName(psOrders.getOd_name());
       return Result.succ("下单成功");

    }

    @RequestMapping("/order/findAll")
    public Result findAllOrders(){
        List<PsOrders> orders = orderService.findAllOrders();
        return Result.succ(orders);
    }

    @RequestMapping("/order/deleted")
    public Result deletedOrdersByName(@RequestParam String ordersName){
        orderService.deletedOrdersByName(ordersName);
        return Result.succ("删除成功");
    }
}
